package com.lagou.guava.controller;

import com.lagou.guava.entity.Position;
import com.lagou.guava.service.PositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.concurrent.ExecutionException;

@Controller
public class IndexController {

    @Autowired
    private PositionService positionService;

    @RequestMapping("/getAll")
    @ResponseBody
    public List<Position> getAll() throws ExecutionException {
        return positionService.getAll();
    }

    @RequestMapping("/index")
    public ModelAndView index(ModelAndView model) throws ExecutionException {
        List<Position> positions = positionService.getAll();
        model.addObject("positions",positions);
        model.setViewName("index");
        return model;
    }
}
